$(function () {
    $(".update-city").on("click", function (e) {
        e.preventDefault();

        var city_id = $(this).parent().parent().find("td:first").html();

        $.ajax({
            url: "/cms2/map/update/all",
            type: 'post',
            data: {
                city_id: city_id
            },
            dataType: 'json',
            success: function (res) {
                if (res.ret == 0) {
                    $('.ret-info').html("更新成功了！<a href='#' onclick='location.reload()'>点此刷新</a>");
                    $(".ret-info").css("color", "green");
                } else {
                    $(".ret-info").html(res.msg);
                    $(".ret-info").css("color", "red");
                }
                scroll(0, 0);
            }
        });
    });

    $(".add-city").on("click", function (e) {
        e.preventDefault();
        var vals = $(".add-table input[type=text]");
        var city_id = $(vals[0]).val();
        var prov_id = $(vals[1]).val();
        var name = $(vals[2]).val();
        var cname = $(vals[3]).val();
        var pos_x = $(vals[4]).val();
        var pos_y = $(vals[5]).val();
        var version = $(vals[6]).val();
        var versioninfo = $(vals[7]).val();
        var bgcolortop = $(vals[8]).val();
        var bgcolorend = $(vals[9]).val();

        $.ajax({
            'url': '/cms2/map/city/add',
            'type': 'post',
            'dataType': 'json',
            'data': {
                city_id: city_id,
                prov_id: prov_id,
                cname: cname,
                name: name,
                pos_x: pos_x,
                pos_y: pos_y,
                version: version,
                versioninfo: versioninfo,
                bgcolortop: bgcolortop,
                bgcolorend: bgcolorend
            },
            'success': function (res) {
                if (res.ret == 0) {
                    $('.ret-info').html("奖励你一个大大的成功:),<a href='#' onclick='location.reload();'>点此刷新</a>。");
                    $(".ret-info").css("color", "green");
                } else {
                    $(".ret-info").html(res.msg);
                    $(".ret-info").css("color", "red");
                }
            },
            'fail': function (res) {
            }
        })
    });
});